/*
 * Copyright 2003-2007 (c) Live Media Pty Ltd. <argot@einet.com.au> 
 *
 * This software is licensed under the Argot Public License 
 * which may be found in the file LICENSE distributed 
 * with this software.
 *
 * More information about this license can be found at
 * http://www.einet.com.au/License
 * 
 * The Developer of this software is Live Media Pty Ltd,
 * PO Box 4591, Melbourne 3001, Australia.  The license is subject 
 * to the law of Victoria, Australia, and subject to exclusive 
 * jurisdiction of the Victorian courts.
 */

package com.colony.networkvm.instruction;


import java.io.IOException;

import com.argot.TypeException;
import com.argot.TypeInputStream;
import com.argot.TypeOutputStream;
import com.argot.TypeReader;
import com.argot.TypeWriter;
import com.argot.remote.MetaLocation;
import com.colony.networkvm.machine.NvmInstance;
import com.colony.remote.RemoteException;

/**
 * The load object will attempt to retrieve an object from a location
 * specified on the heap.
 *
 * The zone object is the first argument.
 * The path String is the second argument.
 */
public class NvmLoadCRLObject
implements NvmInstruction
{
	public static final String TYPENAME = "nvm.instruction.load_crl_object";
	
    public void execute(NvmInstance request) 
    throws RemoteException
    {
    	request.incProgramCounter();
    	        
    	MetaLocation location = (MetaLocation) request.pop();
		// Step 1.  Find the Object & get its type.
		Object o = request.getEnvironment().getHostContainer().getObject( location );
		if ( o == null )
		{
			request.setException( new RemoteException( "no object found") );
			return;
		}

		request.push(o);	
    }

    public static class NvmLoadCRLObjectTypeWriter
    implements TypeWriter
    {
	    public void write(TypeOutputStream out, Object o) throws TypeException, IOException
	    {
	        // empty
	    }
    }

    public static class NvmLoadCRLObjectTypeReader
    implements TypeReader
    {
	    public Object read(TypeInputStream in) throws TypeException, IOException
	    {
	        return new NvmLoadCRLObject();
	    }
    }

}
